1 Imports System.Data.SqlClient
2 Public Class Chuyen_xe
3     Private Ban_ve As New Ban_ve
4     Private bang_chuyen_xe As DataTable
5     Private bang_tuyen_xe As DataTable
6     Private bang_Chi_tiet_tuyen As DataTable
7     Private bang_Thoi_diem As DataTable
8     Private bang_xe As DataTable
9
10     Private lenh As String
11     Private flag As Boolean
12     Private vi_tri_hien_hanh As Integer =
0
13
14
15     Public Sub Update_Chuyen_xe()
16         Doc_chuyen_xe()
17         Tao_lien_ket()
18         Lock_Control(False)
19         vi_tri_hien_hanh =
0
20         Xuat_thong_tin_Chuyen_xe()
21     End Sub
22
23     Private Sub Doc_chuyen_xe()
24         Form_Main.Luoi_Chuyen_xe.ClearSelection()
25         lenh =
"Select * from ChuyenXe"
26         bang_chuyen_xe = Doc_bang(lenh)
27         Form_Main.Luoi_Chuyen_xe.DataSource = bang_chuyen_xe
28     End Sub
29
30     Private Sub Tao_lien_ket()
31         If bang_chuyen_xe.Rows.Count <>
0 Then
32             With Form_Main.cbo_IdChuyen
33                 .DataSource = bang_chuyen_xe
34                 .DisplayMember =
"IdChuyen"
35                 .ValueMember =
"IdChuyen"
36             End With
37             Xoa_lien_ket()
38             Form_Main.cbo_IdChuyen.Text = Form_Main.Luoi_Chuyen_xe.Rows(
0).Cells.Item(0).Value.ToString
39
40             With Form_Main
41                 .cbo_IdTuyenChuyen.DataBindings.Add(
"Text", .Luoi_Chuyen_xe.DataSource, "IdTuyen")
42                 .cbo_SoXeChuyen.DataBindings.Add(
"Text", .Luoi_Chuyen_xe.DataSource, "So_Xe")
43                 .cbo_NgayDiChuyen.DataBindings.Add(
"Text", .Luoi_Chuyen_xe.DataSource, "NgayDi")
44                 .cbo_GioDiChuyen.DataBindings.Add(
"Text", .Luoi_Chuyen_xe.DataSource, "Gio")
45             End With
46         End If
47     End Sub
48
49     Private Sub Xoa_lien_ket()
50         With Form_Main
51             .cbo_IdTuyenChuyen.DataBindings.Clear()
52             .cbo_SoXeChuyen.DataBindings.Clear()
53             .cbo_NgayDiChuyen.DataBindings.Clear()
54             .cbo_GioDiChuyen.DataBindings.Clear()
55         End With
56     End Sub
57
58     Private Sub Lock_Control(ByVal f As Boolean)
59         With Form_Main
60             .cbo_IdChuyen.Enabled = Not f
61             .cbo_IdTuyenChuyen.Enabled = f
62             .cbo_SoXeChuyen.Enabled = f
63             .cbo_NgayDiChuyen.Enabled = f
64             .cbo_GioDiChuyen.Enabled = f
65             .Luoi_Chuyen_xe.Enabled = Not f
66         End With
67     End Sub
68
69     Private Sub Clear_Control()
70         With Form_Main
71             .cbo_IdChuyen.Text =
""
72             .cbo_IdTuyenChuyen.Text =
""
73             .cbo_NgayDiChuyen.Text =
""
74             .cbo_GioDiChuyen.Text =
""
75             .txt_SoDienThoai.Text =
""
76             .cbo_SoXeChuyen.Text =
""
77             .cbo_IdTuyenChuyen.Focus()
78         End With
79     End Sub
80
81     Private Sub LockButton(ByVal dt As Boolean)
82         With Form_Main
83             .btn_ThemChuyen.Enabled = Not dt
84             .btn_SuaChuyen.Enabled = Not dt
85             .btn_XoaChuyen.Enabled = Not dt
86             .btn_LuuChuyen.Enabled = dt
87             .btn_HuyChuyen.Enabled = dt
88         End With
89     End Sub
90
91     Public Sub Them()
92         Xoa_lien_ket()
93         flag = True
94         Lock_Control(True)
95         LockButton(True)
96         Doc_tuyen_xe()
97         Doc_xe()
98         Clear_Control()
99     End Sub
100
101     Public Sub Sua()
102         flag = False
103         Lock_Control(True)
104         LockButton(True)
105         Doc_tuyen_xe()
106         Doc_xe()
107     End Sub
108
109     Public Sub Huy()
110         Xoa_lien_ket()
111         Lock_Control(False)
112         LockButton(False)
113         Update_Chuyen_xe()
114
115     End Sub
116
117     Private Sub Doc_tuyen_xe()
118         lenh =
"Select IdTuyen from TuyenXe"
119         bang_tuyen_xe = Doc_bang(lenh)
120         With Form_Main.cbo_IdTuyenChuyen
121             .DataSource = bang_tuyen_xe
122             .DisplayMember =
"IdTuyen"
123             .ValueMember =
"IdTuyen"
124         End With
125     End Sub
126
127     Public Sub Chon_tuyen()
128         If Form_Main.cbo_IdTuyenChuyen.SelectedIndex <
0 Then Exit Sub 'Nghia la ko chọn mục nào
129         Loc_Thoi_diem_theo_Tuyen(Form_Main.cbo_IdTuyenChuyen.SelectedValue.ToString)
130     End Sub
131
132     Private Sub Loc_Thoi_diem_theo_Tuyen(ByVal IdTuyen As String)
133         lenh =
"Select Distinct Ngay from ThoiDiem, ChiTietTuyen where IdTuyen = '" + IdTuyen + "' and ThoiDiem.IdThoiDiem = ChiTietTuyen.IdThoiDiem"
134         bang_Chi_tiet_tuyen = Doc_bang(lenh)
135         With Form_Main.cbo_NgayDiChuyen
136             .DataSource = bang_Chi_tiet_tuyen
137             .ValueMember =
"Ngay"
138             .DisplayMember =
"Ngay"
139         End With
140     End Sub
141
142     Public Sub Chon_ngay()
143         If Form_Main.cbo_NgayDiChuyen.SelectedIndex <
0 Then Exit Sub 'Nghia la ko chọn mục nào
144         Loc_gio_theo_ngay(Form_Main.cbo_NgayDiChuyen.SelectedValue.ToString)
145     End Sub
146
147     Private Sub Loc_gio_theo_ngay(ByVal ngay As String)
148         lenh =
"Select Gio from ThoiDiem where Ngay = '" + ngay + "'"
149         bang_Thoi_diem = Doc_bang(lenh)
150         With Form_Main.cbo_GioDiChuyen
151             .DataSource = bang_Thoi_diem
152             .ValueMember =
"Gio"
153             .DisplayMember =
"Gio"
154         End With
155     End Sub
156
157     Private Sub Doc_xe()
158         lenh =
"Select So_Xe from Xe"
159         bang_xe = Doc_bang(lenh)
160         With Form_Main.cbo_SoXeChuyen
161             .DataSource = bang_xe
162             .ValueMember =
"So_Xe"
163             .DisplayMember =
"So_Xe"
164         End With
165     End Sub
166
167     Public Sub Luu()
168         If connect.State = ConnectionState.Open Then
169             connect.Close()
170         End If
171         With Form_Main
172             If flag = True Then
'Truong hop them chuyen moi
173                 If TestInfo() Then
174                     Dim dg As DialogResult = MessageBox.Show(
"Ban có chắn chắc muốn thêm chuyến xe này không, " & vbNewLine _
175                                ,
"Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
176                     If dg = Windows.Forms.DialogResult.Yes Then
'Neu nhan vien dong y
177                         
'Kiem tra xem chuyen xe do co bi trung khong
178                         Dim sqlCM As New SqlCommand(
"select IdTuyen, NgayDi, Gio, So_Xe from ChuyenXe", connect)
179                         Dim sqlDR As SqlDataReader
180                         connect.Open()
181                         sqlDR = sqlCM.ExecuteReader
182                         While sqlDR.Read() = True
183                             If sqlDR.GetValue(
0).ToString = .cbo_IdTuyenChuyen.Text AndAlso FormatDateTime(CDate(sqlDR.GetValue(1)), DateFormat.ShortDate) = .cbo_NgayDiChuyen.Text AndAlso sqlDR.GetValue(2).ToString = .cbo_GioDiChuyen.Text AndAlso sqlDR.GetValue(3).ToString = .cbo_SoXeChuyen.Text Then
184                                 MessageBox.Show(
"Xe " + .cbo_SoXeChuyen.Text + " đã được gán cho tuyến " + .cbo_IdTuyenChuyen.Text + " vào thời điểm này rồi, vui lòng chọn xe khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning)
185                                 connect.Close()
186                                 Exit Sub
187                             End If
188                             
'Kiem tra hai gio chay cua xe do trong ngay khong duoc chenh lech it nhat la quá 3 tiếng
189                             If FormatDateTime(CDate(sqlDR.GetValue(
1)), DateFormat.ShortDate) = .cbo_NgayDiChuyen.Text AndAlso sqlDR.GetValue(3).ToString = .cbo_SoXeChuyen.Text Then
190                                 
'Cat chuoi gio cua chuyen da co va gio cua chuyen muon them moi
191                                 Dim gioDaCo As String = sqlDR.GetValue(
2).ToString
192                                 Dim gioMuonThem As String = .cbo_GioDiChuyen.Text
193                                 Dim i, j As Integer
194                                 If gioDaCo.Length =
4 And gioMuonThem.Length = 4 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
195                                     i = CInt(Strings.Left(gioDaCo,
1))
196                                     j = CInt(Strings.Left(gioMuonThem,
1))
197                                     If i - j <
3 OrElse j - i < 3 Then
198                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
199                                         connect.Close()
200                                         Exit Sub
201                                     End If
202                                 End If
203
204                                 If gioDaCo.Length =
2 And gioMuonThem.Length = 2 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
205                                     i = CInt(Strings.Left(gioDaCo,
1))
206                                     j = CInt(Strings.Left(gioMuonThem,
1))
207                                     If i - j <
3 OrElse j - i < 3 Then
208                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
209                                         connect.Close()
210                                         Exit Sub
211                                     End If
212                                 End If
213
214                                 If gioDaCo.Length =
3 And gioMuonThem.Length = 2 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
215                                     i = CInt(Strings.Left(gioDaCo,
2))
216                                     j = CInt(Strings.Left(gioMuonThem,
1))
217                                     If i - j <
3 OrElse j - i < 3 Then
218                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
219                                         connect.Close()
220                                         Exit Sub
221                                     End If
222                                 End If
223
224                                 If gioDaCo.Length =
2 And gioMuonThem.Length = 3 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
225                                     i = CInt(Strings.Left(gioDaCo,
1))
226                                     j = CInt(Strings.Left(gioMuonThem,
2))
227                                     If i - j <
3 OrElse j - i < 3 Then
228                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
229                                         connect.Close()
230                                         Exit Sub
231                                     End If
232                                 End If
233
234                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
235                                     i = CInt(Strings.Left(gioDaCo,
2))
236                                     j = CInt(Strings.Left(gioMuonThem,
2))
237                                     If i - j <
3 OrElse j - i < 3 Then
238                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
239                                         connect.Close()
240                                         Exit Sub
241                                     End If
242                                 End If
243
244                                 If gioDaCo.Length =
2 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
245                                     i = CInt(Strings.Left(gioDaCo,
1))
246                                     j = CInt(Strings.Left(gioMuonThem,
2))
247                                     If i - j <
3 OrElse j - i < 3 Then
248                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
249                                         Exit Sub
250                                     End If
251                                 End If
252
253                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 2 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
254                                     i = CInt(Strings.Left(gioDaCo,
2))
255                                     j = CInt(Strings.Left(gioMuonThem,
1))
256                                     If i - j <
3 OrElse j - i < 3 Then
257                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
258                                         connect.Close()
259                                         Exit Sub
260                                     End If
261                                 End If
262
263                                 If gioDaCo.Length =
3 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
264                                     i = CInt(Strings.Left(gioDaCo,
2))
265                                     j = CInt(Strings.Left(gioMuonThem,
2))
266                                     If i - j <
3 OrElse j - i < 3 Then
267                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
268                                         connect.Close()
269                                         Exit Sub
270                                     End If
271                                 End If
272
273                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 3 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
274                                     i = CInt(Strings.Left(gioDaCo,
2))
275                                     j = CInt(Strings.Left(gioMuonThem,
2))
276                                     If i - j <
3 OrElse j - i < 3 Then
277                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
278                                         connect.Close()
279                                         Exit Sub
280                                     End If
281                                 End If
282
283                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 4 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
284                                     i = CInt(Strings.Left(gioDaCo,
2))
285                                     j = CInt(Strings.Left(gioMuonThem,
2))
286                                     If i - j <
3 OrElse j - i < 3 Then
287                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
288                                         connect.Close()
289                                         Exit Sub
290                                     End If
291                                 End If
292
293                                 If gioDaCo.Length =
4 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
294                                     i = CInt(Strings.Left(gioDaCo,
2))
295                                     j = CInt(Strings.Left(gioMuonThem,
2))
296                                     If i - j <
3 OrElse j - i < 3 Then
297                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
298                                         connect.Close()
299                                         Exit Sub
300                                     End If
301                                 End If
302                             End If
303                             
'Neu muon kiem tra gi nua thi them o day
304                         End While
305                         connect.Close()
306
307                         
'Bat dau insert dulieu
308                         lenh =
"Insert into ChuyenXe(IdTuyen, NgayDi, Gio, So_Xe)"
309                         lenh &=
" Values ('" + .cbo_IdTuyenChuyen.Text + "', '" + .cbo_NgayDiChuyen.Text + "', '" + .cbo_GioDiChuyen.Text + "', '" + .cbo_SoXeChuyen.Text + "')"
310                         Dim bo_lenh As New SqlCommand(lenh, connect)
311                         connect.Open()
312                         Try
313                             bo_lenh.ExecuteNonQuery()
314                             connect.Close()
315                             Update_Chuyen_xe()
316                             Lock_Control(False)
317                             LockButton(False)
318                             Form_Main.Luoi_Chuyen_xe.Enabled = True
319                             MsgBox(
"Đã cập nhật dữ liệu thành công", MsgBoxStyle.Information, "Thông báo")
320                         Catch ex As Exception
321                             MessageBox.Show(
"Không cập nhật được dữ liệu, thêm chuyen thông thành công.", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
322                             connect.Close()
323                         End Try
324                     Else
325                         Huy()
326                     End If
327                 End If
328             Else
'Truong hop sua thong tin chuyen
329                 If TestInfo() Then
330                     Dim dg As DialogResult = MessageBox.Show(
"Ban có chắn chắc muốn sửa thông tin chuyến xe này không, " & vbNewLine _
331                                ,
"Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
332                     If dg = Windows.Forms.DialogResult.Yes Then
'Neu nhan vien dong y
333                         Dim sqlCM As New SqlCommand(
"select IdTuyen, NgayDi, Gio, So_Xe from ChuyenXe", connect)
334                         Dim sqlDR As SqlDataReader
335                         connect.Open()
336                         sqlDR = sqlCM.ExecuteReader
337                         While sqlDR.Read() = True
338                             If sqlDR.GetValue(
0).ToString = .cbo_IdTuyenChuyen.Text AndAlso FormatDateTime(CDate(sqlDR.GetValue(1)), DateFormat.ShortDate) = .cbo_NgayDiChuyen.Text AndAlso sqlDR.GetValue(2).ToString = .cbo_GioDiChuyen.Text AndAlso sqlDR.GetValue(3).ToString = .cbo_SoXeChuyen.Text Then
339                                 MessageBox.Show(
"Xe " + .cbo_SoXeChuyen.Text + " đã được gán cho tuyến " + .cbo_IdTuyenChuyen.Text + " vào thời điểm này rồi, vui lòng chọn xe khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning)
340                                 connect.Close()
341                                 Exit Sub
342                             End If
343                             
'Kiem tra hai gio chay cua xe do trong ngay khong duoc chenh lech it nhat la quá 3 tiếng
344                             If FormatDateTime(CDate(sqlDR.GetValue(
1)), DateFormat.ShortDate) = .cbo_NgayDiChuyen.Text AndAlso sqlDR.GetValue(3).ToString = .cbo_SoXeChuyen.Text Then
345                                 
'Cat chuoi gio cua chuyen da co va gio cua chuyen muon them moi
346                                 Dim gioDaCo As String = sqlDR.GetValue(
2).ToString
347                                 Dim gioMuonThem As String = .cbo_GioDiChuyen.Text
348                                 Dim i, j As Integer
349                                 If gioDaCo.Length =
4 And gioMuonThem.Length = 4 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
350                                     i = CInt(Strings.Left(gioDaCo,
1))
351                                     j = CInt(Strings.Left(gioMuonThem,
1))
352                                     If i - j <
3 OrElse j - i < 3 Then
353                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
354                                         connect.Close()
355                                         Exit Sub
356                                     End If
357                                 End If
358
359                                 If gioDaCo.Length =
2 And gioMuonThem.Length = 2 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
360                                     i = CInt(Strings.Left(gioDaCo,
1))
361                                     j = CInt(Strings.Left(gioMuonThem,
1))
362                                     If i - j <
3 OrElse j - i < 3 Then
363                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
364                                         connect.Close()
365                                         Exit Sub
366                                     End If
367                                 End If
368
369                                 If gioDaCo.Length =
3 And gioMuonThem.Length = 2 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
370                                     i = CInt(Strings.Left(gioDaCo,
2))
371                                     j = CInt(Strings.Left(gioMuonThem,
1))
372                                     If i - j <
3 OrElse j - i < 3 Then
373                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
374                                         connect.Close()
375                                         Exit Sub
376                                     End If
377                                 End If
378
379                                 If gioDaCo.Length =
2 And gioMuonThem.Length = 3 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
380                                     i = CInt(Strings.Left(gioDaCo,
1))
381                                     j = CInt(Strings.Left(gioMuonThem,
2))
382                                     If i - j <
3 OrElse j - i < 3 Then
383                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
384                                         connect.Close()
385                                         Exit Sub
386                                     End If
387                                 End If
388
389                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
390                                     i = CInt(Strings.Left(gioDaCo,
2))
391                                     j = CInt(Strings.Left(gioMuonThem,
2))
392                                     If i - j <
3 OrElse j - i < 3 Then
393                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
394                                         connect.Close()
395                                         Exit Sub
396                                     End If
397                                 End If
398
399                                 If gioDaCo.Length =
2 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 2, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
400                                     i = CInt(Strings.Left(gioDaCo,
1))
401                                     j = CInt(Strings.Left(gioMuonThem,
2))
402                                     If i - j <
3 OrElse j - i < 3 Then
403                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
404                                         Exit Sub
405                                     End If
406                                 End If
407
408                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 2 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 2, 1) = "h" Then
409                                     i = CInt(Strings.Left(gioDaCo,
2))
410                                     j = CInt(Strings.Left(gioMuonThem,
1))
411                                     If i - j <
3 OrElse j - i < 3 Then
412                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
413                                         connect.Close()
414                                         Exit Sub
415                                     End If
416                                 End If
417
418                                 If gioDaCo.Length =
3 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
419                                     i = CInt(Strings.Left(gioDaCo,
2))
420                                     j = CInt(Strings.Left(gioMuonThem,
2))
421                                     If i - j <
3 OrElse j - i < 3 Then
422                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
423                                         connect.Close()
424                                         Exit Sub
425                                     End If
426                                 End If
427
428                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 3 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
429                                     i = CInt(Strings.Left(gioDaCo,
2))
430                                     j = CInt(Strings.Left(gioMuonThem,
2))
431                                     If i - j <
3 OrElse j - i < 3 Then
432                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
433                                         connect.Close()
434                                         Exit Sub
435                                     End If
436                                 End If
437
438                                 If gioDaCo.Length =
5 And gioMuonThem.Length = 4 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
439                                     i = CInt(Strings.Left(gioDaCo,
2))
440                                     j = CInt(Strings.Left(gioMuonThem,
2))
441                                     If i - j <
3 OrElse j - i < 3 Then
442                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
443                                         connect.Close()
444                                         Exit Sub
445                                     End If
446                                 End If
447
448                                 If gioDaCo.Length =
4 And gioMuonThem.Length = 5 AndAlso Strings.Mid(gioDaCo, 3, 1) = "h" AndAlso Strings.Mid(gioMuonThem, 3, 1) = "h" Then
449                                     i = CInt(Strings.Left(gioDaCo,
2))
450                                     j = CInt(Strings.Left(gioMuonThem,
2))
451                                     If i - j <
3 OrElse j - i < 3 Then
452                                         MessageBox.Show(
"Một xe chạy trong cùng 1 ngày không được có thời gian cách nhau nhỏ hơn 3 tiếng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
453                                         connect.Close()
454                                         Exit Sub
455                                     End If
456                                 End If
457                             End If
458                             
'Neu muon kiem tra gi nua thi them o day
459                         End While
460                         connect.Close()
461                         Dim dr As SqlDataReader
462                         Dim lenh3 As String =
"Select IdChuyen from ChoNgoi"
463                         Dim bo_lenh As New SqlCommand(lenh3, connect)
464                         connect.Open()
465                         dr = bo_lenh.ExecuteReader
466                         While dr.Read = True
467                             If dr.GetValue(
0).ToString = .cbo_IdChuyen.Text Then
468                                 MessageBox.Show(
"Chuyến xe đã có nguoi đặt chỗ rồi, bạn không được sưa vì sẽ làm mất uy tính khách hàng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error)
469                                 connect.Close()
470                                 Exit Sub
471                             End If
472                         End While
473                         connect.Close()
474                         lenh =
"Update ChuyenXe Set IdTuyen = '" + .cbo_IdTuyenChuyen.Text + "', NgayDi = '" + .cbo_NgayDiChuyen.Text + "', Gio = '" + .cbo_GioDiChuyen.Text + "', So_Xe = '" + .cbo_SoXeChuyen.Text + "' where IdChuyen = '" + .cbo_IdTuyenChuyen.Text + "'"
475                         Dim sqlqr As New SqlCommand(lenh, connect)
476                         Try
477                             connect.Open()
478                             sqlqr.ExecuteNonQuery()
479                             connect.Close()
480                             Update_Chuyen_xe()
481                             Lock_Control(False)
482                             LockButton(False)
483                             Form_Main.Luoi_Chuyen_xe.Enabled = True
484                             MsgBox(
"Đã cập nhật dữ liệu thành công", MsgBoxStyle.Information, "Thông báo")
485                         Catch ex As Exception
486                             MessageBox.Show(
"Không cập nhật được dữ liệu, sửa thông tin chuyen xe thông thành công.", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
487                             connect.Close()
488                         End Try
489                     Else
490                         Huy()
491                     End If
492                 End If
493             End If
494         End With
495         Ban_ve.Update_Ve_xe()
496     End Sub
497
498     Private Function TestInfo() As Boolean
499         TestInfo = True
500         With Form_Main
501             If Trim(.cbo_IdTuyenChuyen.Text) =
"" OrElse Trim(.cbo_NgayDiChuyen.Text) = "" OrElse Trim(.cbo_GioDiChuyen.Text) = "" _
502             OrElse Trim(.cbo_SoXeChuyen.Text) =
"" Then
503                 TestInfo = False
504                 MsgBox(
"Bạn phải nhập đầy đủ thông tin!", MsgBoxStyle.Exclamation, "Thông báo lỗi")
505             End If
506
507             If Trim(.cbo_IdTuyenChuyen.Text) =
"" Then
508                 .cbo_IdTuyenChuyen.Focus()
509                 Exit Function
510             ElseIf Trim(.cbo_NgayDiChuyen.Text) =
"" Then
511                 .cbo_NgayDiChuyen.Focus()
512                 Exit Function
513             ElseIf Trim(.cbo_GioDiChuyen.Text) =
"" Then
514                 .cbo_GioDiChuyen.Focus()
515                 Exit Function
516             ElseIf Trim(.cbo_SoXeChuyen.Text) =
"" Then
517                 .cbo_SoXeChuyen.Focus()
518                 Exit Function
519             End If
520         End With
521     End Function
522
523     Public Sub Xoa()
524         Dim qs = MessageBox.Show(
"Bạn chắc chắn muốn xóa tất cả thông tin về:" & vbNewLine & _
525                         
" - Chuyến xe: " & Form_Main.cbo_IdChuyen.Text & vbNewLine & _
526                         
" - Tuyến xe: " & Form_Main.cbo_IdTuyenChuyen.Text, "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
527         If qs = DialogResult.Yes Then
528             Dim lenh As String =
"Delete from ChuyenXe where IdChuyen = '" & Form_Main.cbo_IdChuyen.SelectedValue.ToString & "'"
529             Dim query1 As New SqlCommand(lenh, connect)
530             Try
531                 connect.Open()
532                 query1.ExecuteNonQuery()
533                 connect.Close()
534                 Update_Chuyen_xe()
535                 MsgBox(
"Dữ liệu đã xóa thành công", vbInformation, "Thông báo")
536             Catch ex As Exception
537                 MsgBox(
"Không cập nhật được dữ liệu, xóa chuyến không thành công", vbExclamation, "Thông báo")
538             End Try
539         Else
540             MsgBox(
"Đã hủy thao tác xóa!", vbExclamation, "Thông báo")
541         End If
542     End Sub
543
544 #Region
"Xu ly cac nut di chuyen va xuat thong tin xe da hoan tat"
545     Private Sub Xuat_thong_tin_Chuyen_xe()
546         If bang_chuyen_xe.Rows.Count <>
0 Then
547             Dim dong As DataRow = bang_chuyen_xe.Rows(vi_tri_hien_hanh)
548             With Form_Main
549                 .cbo_IdChuyen.Text = dong(
"IdChuyen").ToString
550                 .cbo_IdTuyenChuyen.Text = dong(
"IdTuyen").ToString
551                 .cbo_NgayDiChuyen.Text = CStr(dong(
"NgayDi"))
552                 .cbo_GioDiChuyen.Text = dong(
"Gio").ToString
553             End With
554         End If
555        
556     End Sub
557
558     Public Sub Di_chuyen_ve_sau()
559         If vi_tri_hien_hanh < bang_chuyen_xe.Rows.Count -
1 Then
560             vi_tri_hien_hanh +=
1
561             Xuat_thong_tin_Chuyen_xe()
562         End If
563     End Sub
564
565     Public Sub Di_chuyen_ve_truoc()
566         If vi_tri_hien_hanh >
0 Then
567             vi_tri_hien_hanh -=
1
568             Xuat_thong_tin_Chuyen_xe()
569         End If
570     End Sub
571
572     Public Sub Di_chuyen_ve_dau()
573         vi_tri_hien_hanh =
0
574         Xuat_thong_tin_Chuyen_xe()
575     End Sub
576
577     Public Sub Di_chuyen_ve_cuoi()
578         vi_tri_hien_hanh = bang_chuyen_xe.Rows.Count -
1
579         Xuat_thong_tin_Chuyen_xe()
580     End Sub
581 #End Region
582
583 End Class



Quản lý phần mềm bán vé xe VB 8.385 lượt xem

Gõ tìm kiếm nhanh...